package pe.edu.unmsm.fiee.sispagos.presentacion.controller.mantenimiento;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.faces.event.ActionEvent;

import org.primefaces.event.SelectEvent;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import pe.edu.unmsm.fiee.sispagos.negocio.modelo.ConceptoPagoDTO;
import pe.edu.unmsm.fiee.sispagos.negocio.servicio.ConceptoPagoService;

@Controller
@Scope("view")
public class ManteConceptoController {

	private String msjeCpto;
	private String labelCpto;
	private ConceptoPagoDTO cptoEditar;
	private List<ConceptoPagoDTO> listCptos;
	private String strBuscarCpto;

	@Resource
	ConceptoPagoService conceptoService;
	
	
	public ManteConceptoController() {
		super();
		setCptoEditar(new ConceptoPagoDTO());
		setStrBuscarCpto("");
	}

	public void nuevoCpto(ActionEvent ev){
		setCptoEditar(new ConceptoPagoDTO());
	}
	
	public void guardarNuevoCpto(){
		setMsjeCpto(conceptoService.guardarCpto(getCptoEditar()));
		setCptoEditar(new ConceptoPagoDTO());
	}
	
	public List<String> completarCptoPago(String query) {  
        List<String> results = new ArrayList<String>();  
        setListCptos(conceptoService.listarCptosxNombre(query));
        for (ConceptoPagoDTO cptoDTO : getListCptos()) {
			results.add(cptoDTO.getNombreCptoPago());
		}
        return results;  
    }

	public void asignarCodCpto(SelectEvent sev){
		for (ConceptoPagoDTO cptoDTO : getListCptos()) {
			String temp=new String(cptoDTO.getNombreCptoPago());
			if(strBuscarCpto.equals(temp))
				setCptoEditar(cptoDTO);
		}
		setLabelCpto("label label-success");
	}
	/******************GETTERS AND SETTERS*******************/
	
	public String getMsjeCpto() {
		return msjeCpto;
	}


	public void setMsjeCpto(String msjeCpto) {
		this.msjeCpto = msjeCpto;
	}


	public String getLabelCpto() {
		return labelCpto;
	}


	public void setLabelCpto(String labelCpto) {
		this.labelCpto = labelCpto;
	}


	public ConceptoPagoDTO getCptoEditar() {
		return cptoEditar;
	}


	public void setCptoEditar(ConceptoPagoDTO cptoEditar) {
		this.cptoEditar = cptoEditar;
	}

	public List<ConceptoPagoDTO> getListCptos() {
		return listCptos;
	}

	public void setListCptos(List<ConceptoPagoDTO> listCptos) {
		this.listCptos = listCptos;
	}

	public String getStrBuscarCpto() {
		return strBuscarCpto;
	}

	public void setStrBuscarCpto(String strBuscarCpto) {
		this.strBuscarCpto = strBuscarCpto;
	}
}
